#include "SFile.h"

SFile::SFile()
{
}


SFile::~SFile()
{
}


set<string> SFile::GetAllFilePath(string dirPath)
{
	path dir(dirPath);
	set<string> dir_set;
	for (recursive_directory_iterator end, ite(dir); ite != end; ++ite)
	{
		if (!is_directory(ite->path()))
		{
			string file = ite->path().string();
			string back = file.substr(file.find_last_of(".") + 1);
			if (back == "cpp" || back == "h" || back == "c")
				dir_set.insert(file);
		}
	}
	return dir_set;
}

bool SFile::SetReadCharFile(string filePath)
{
	readCharFile = filePath;
	if (readCharFile.empty())
		return false;
	fs.open(readCharFile, ios::in);
	if (!fs.is_open())
		return false;
	return true;
}

void SFile::CloseReadCharFile()
{
	fs.close();
}

char SFile::GetNextChar()
{
	char ch;
	if (!fs.eof())
	{
		ch = fs.get();
		return ch;
	}
	return -1;
}

bool SFile::GetNextChar(char ch)
{
	char c;
	if ((c = GetNextChar()) != -1)
	{
		if (c == ch)
			return true;
		else
			return false;
	}
	return false;
}
void SFile::BackFileSeek(void)
{
	fs.seekg(-1,ios::cur);
}